package com.whj.controller;

import com.whj.domain.entity.Article;
import com.whj.domain.response.ResponseResult;
import com.whj.domain.vo.ArticleDetailVo;
import com.whj.domain.vo.ArticleListVo;
import com.whj.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: wanghaijun
 * @Date: 2023/5/21 - 05 - 21 - 22:13 
 * @Description: com.whj.controller
 */

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 查询热门文章
     *
     * @return 返回ArticleList
     */
    @GetMapping("/hotArticleList")
    public ResponseResult<Article> hotArticleList() {
        return articleService.hotArticleList();
    }

    @GetMapping("/articleList")
    public ResponseResult<ArticleListVo> articleList(Integer pageNum, Integer pageSize, Long categoryId) {
        return articleService.articleList(pageNum, pageSize, categoryId);
    }

    @GetMapping("/{id}")
    public ResponseResult<ArticleDetailVo> getArticleDetail(@PathVariable("id") Long id) {
        return articleService.getArticleDetail(id);
    }

    /**
     * 更新文章的浏览量 （数据提前存入redis中）
     *  更新redis的数据
     *
     * @param id
     * @return
     */
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){

        return articleService.updateViewCount(id);
    }

}
